package hot100.二叉树直径;

import hot100.TreeNode;

/**
 * @author llt
 * @date 2025/4/30
 */
public class Test {
    int result;

    public int diameterOfBinaryTree(TreeNode root) {
        result = 1;
        depth(root);
        return result - 1;
    }

    private int depth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int L = depth(root.left);
        int R = depth(root.right);
        result = Math.max(result, L + R + 1);
        return Math.max(L, R) + 1;
    }
}
